Page({
  data: {
    openid:"",
    name:"",
    phone:"",
    id:"",
    jhr:[],
    sfz:"", //身份证号
    age:""  // 计算的年龄
  },
  onLoad(){
    // 导航栏
    // 1.获取屏幕可使用宽度
    let windowWidth = wx.getSystemInfoSync().windowWidth;
    // 2.获取状态栏高度
    const statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
    //3.获取胶囊按钮位置信息
    const menuButton = wx.getMenuButtonBoundingClientRect();
    this.setData({
      navtop:menuButton.top,
      openid:getApp().globalData.openid
    })
    wx.request({
      url: 'https://dj.ifankui.com/api/usr/getProfile',
      method:"POST",
      data:{
        openid:this.data.openid
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success:(res)=>{
        console.log(res);
        this.setData({
          name:res.data.data.lrxm,
          phone:res.data.data.lrdh,
          id:res.data.data.id,
          jhr:res.data.data.jhr,
          sfz:res.data.data.lrsfz,
        })

        // 提取出生年月日
        let birthYear = parseInt(this.data.sfz.substring(6, 10));
        let birthMonth = parseInt(this.data.sfz.substring(10, 12));
        let birthDay = parseInt(this.data.sfz.substring(12, 14));
        // 获取当前日期
        let today = new Date();
        let currentYear = today.getFullYear();
        let currentMonth = today.getMonth() + 1; 
        let currentDay = today.getDate();
        // 计算年龄
        let age = currentYear - birthYear;
        if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
            age -= +1; // 如果当前日期小于出生日期，则年龄减一
        }
        this.setData({
          age:age
        })
      }
    })
  },
  gitfor(){
    wx.navigateBack({
      delta: -1
    })
  },
  bddh(e){
    console.log(e);
    wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.phone
    })
},
bangding1() {
  wx.navigateTo({
    url: '../user/user',
  })
},

})